window.addEventListener('load',function() {
	$('#title').append("<h1>" + capitalise(localStorage.getItem("estudia_course")) + "</h1>");
	
	var judul_bab;
	
	$.get( "../subbab.json", function( data ) {
	  for (var i = 1; i <= (data[localStorage.getItem("estudia_course")]["length"]); i++) {
		judul_bab = data[localStorage.getItem("estudia_course")][i];
		$('#menu_bab').append("<button type=\"button\" id=\"courses_chapter\" value=\"" + i + "-" + judul_bab + "\" onclick=\"chapter_click(this.value)\">" + (judul_bab) + "</button><br />");
		
	  } // */
	});
});

function capitalise(string) {
	return string.charAt(0).toUpperCase() + string.slice(1);
};

function chapter_click(chapter) {
	//alert(chapter);
	//localStorage.setItem("estudia_chapter", chapter);
	var maxPage = 0;
	$.get( "../partmateri.json", function( data ) {
		maxPage = data[localStorage.getItem("estudia_course")][chapter.charAt(0)];
		//alert(maxPage);
		localStorage.setItem("estudia_maxpage", maxPage);
	}).done(function() {
		localStorage.setItem("estudia_chapter", chapter);
		if (localStorage.getItem("estudia_type") == "materi") {
			if (maxPage == "0") {
				
			} else {
				window.location.href = 'tampilanmateri.html?page=1';
			}
		} else if (localStorage.getItem("estudia_type") == "soal") {
			if (chapter.charAt(0) == "1") {
				localStorage.setItem("estudia_ans_right", 0);
				localStorage.setItem("estudia_ans_false", 0);
				window.location.href = 'tampilansoal.html?page=1';
			} else {
				
			}
		} else {
			window.location.href = '../index.html';
		}
		
	}); // */
}